-
Notifications
You must be signed in to change notification settings - Fork 147
Replace Done callback with CompletableFuture result
#2051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Done callback with CompletableFuture result
#2051
Conversation
...dles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java
Outdated
Show resolved
Hide resolved
...dles/org.eclipse.terminal.view.core/src/org/eclipse/terminal/view/core/ITerminalService.java
Outdated
Show resolved
Hide resolved
e8a617b to
161c5e8
Compare
Done callback to stop accepting nullCompletableFuture result
CompletableFuture resultDone callback with CompletableFuture result
...rg.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/ILauncherDelegate.java
Outdated
Show resolved
Hide resolved
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laeubi may be we should return IStatus here to simplify caller's life?
I think a CF is better to reflect the async nature of this, but using IStatus at all seems questionable to me. an anonymous CompletableFuture<?> that simply is failed on any error seems more appropriate.. if we feel to pass a status a CoreException can then be used.
...connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java
Outdated
Show resolved
Hide resolved
...connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java
Outdated
Show resolved
Hide resolved
....connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherHandler.java
Show resolved
Hide resolved
.../org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java
Show resolved
Hide resolved
.../org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java
Outdated
Show resolved
Hide resolved
....view.ui/src/org/eclipse/terminal/view/ui/internal/handler/LaunchTerminalCommandHandler.java
Outdated
Show resolved
Hide resolved
...view.ui/src/org/eclipse/terminal/view/ui/internal/local/showin/DynamicContributionItems.java
Outdated
Show resolved
Hide resolved
...pse.terminal.view.ui/src/org/eclipse/terminal/view/ui/launcher/AbstractLauncherDelegate.java
Outdated
Show resolved
Hide resolved
5361f03 to
09863d2
Compare
|
Now the snippet is @laeubi try {
delegate.execute(properties);
} catch (Exception e) {
throw new ExecutionException(e.getMessage(), e);
//or log
} |
...tor.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java
Outdated
Show resolved
Hide resolved
.../org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java
Outdated
Show resolved
Hide resolved
Currently `null` is tolerated as a callback for a number of terminal-related operations. Moreover, it seems that callers prefer to avoid any callback. Replace rarely used callback with completable future result.
09863d2 to
00f2335
Compare
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine for me now
| if (runnable.isExecuteAsync()) { | ||
| return CompletableFuture.supplyAsync(() -> runnable.run(tvid, title, connector, data), | ||
| Display.getDefault()); | ||
| } else { | ||
| try { | ||
| Display display = PlatformUI.getWorkbench().getDisplay(); | ||
| display.asyncExec(() -> runnable.run(tvid, title, connector, data, done)); | ||
| } catch (Exception e) { | ||
| // if display is disposed, silently ignore. | ||
| } | ||
| return CompletableFuture.completedFuture(runnable.run(tvid, title, connector, data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that effectively both of the branches of this if statement run the runnable immediately instead of queuing it on the display queue.
See #2155 (comment)
and Display.execute(Runnable) which is used by asyncSupplyStage. When Display.execute is called on the UI thread, then the runnable is run immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Display.execute is called on the UI thread, then the runnable is run immediately.
That's indeed the case... I think one can simply pass in display::asyncExec as the executor to get the desired effect as before.
Currently
nullis tolerated as a callback for a number of terminal-related operations. The introduced empty implementationNOOPallows to prohibitnullas a callback argument.